package com.redoor.app.stake.basicdata.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.redoor.app.stake.basicdata.model.BaseRegistrationApply;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseRegistrationApplyCriteria;
import com.redoor.app.stake.basicdata.service.BaseRegistrationApplyService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-08 16:34:23.
*/
@RestController
@RequestMapping("/base/registration/applys")
public class BaseRegistrationApplyController {

    @Autowired
    private BaseRegistrationApplyService baseRegistrationApplyService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseRegistrationApply baseRegistrationApply) {
        baseRegistrationApplyService.save(baseRegistrationApply);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        baseRegistrationApplyService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody BaseRegistrationApply baseRegistrationApply) {
        baseRegistrationApplyService.updateBySelective(baseRegistrationApply);
        return ResultGenerator.generatorSuccess();
    }
    @ApiOperation(value = "注册码详情,传值:id='主键'")
    @PostMapping("/detail")
    public ResponseResult detail( String id) {
        BaseRegistrationApply baseRegistrationApply = baseRegistrationApplyService.detail(id);
        return ResultGenerator.generatorSuccess(baseRegistrationApply);
    }

    @GetMapping
    public ResponseResult list(BaseRegistrationApplyCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<BaseRegistrationApply> list = baseRegistrationApplyService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
